package com.xzs.thinking.dao.impl;

import com.xzs.thinking.dao.HelloWorldDao;
import com.xzs.thinking.model.HelloWorldVO;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * @author : Iris.Xiao
 * @date : 2017/11/17 16:47
 * @description :
 */
@Repository
public class HelloWorldDaoImpl implements HelloWorldDao {
//    @Autowired

    @Resource(name="primaryJdbcTemplate")
//    @Qualifier("primaryJdbcTemplate")
    private JdbcTemplate jdbcTemplate;

    @Resource(name="secondaryJdbcTemplate")
//    @Qualifier("secondaryJdbcTemplate")
    protected JdbcTemplate jdbcTemplate2;

    public HelloWorldVO getById(String id){
        String sql = "select * from bbs_article where article_id=?";
        RowMapper<HelloWorldVO> rowMapper = new BeanPropertyRowMapper<HelloWorldVO>(HelloWorldVO.class);
        return jdbcTemplate.queryForObject(sql, rowMapper,id);
    }

    public HelloWorldVO getByIdDataSource2(String id){
        String sql = "select * from bbs_article where article_id=?";
        RowMapper<HelloWorldVO> rowMapper = new BeanPropertyRowMapper<HelloWorldVO>(HelloWorldVO.class);
        return jdbcTemplate2.queryForObject(sql, rowMapper,id);
    }
}
